package com.hubei.servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author PJM
 * @date 2025/6/23-15:19
 */
@WebServlet("/test_one")
public class TestServlet extends HttpServlet {
    @Override
    public void init(ServletConfig config) throws ServletException {

    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 将包含在请求对象中的信息，处理成字符集为utf-8的格式，为了解决中文乱码
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        // 输出的打印流
        PrintWriter writer = response.getWriter();
        writer.println("<!DOCTYPE html>");
        writer.println("<html>");
        writer.println("<head>");
        writer.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
        writer.println("<title>Insert title here</title>");
        writer.println("</head>");
        writer.println("<body>");
        writer.println("<h1 style=\"color: red;\">由Servlet生成动态页面</h1>");
        writer.println("<p>一段文本内容</p>");
        writer.println("</body>");
        writer.println("</html>");
    }
}
